home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / PowerMacOberon feb96 / Source / Bitmaps.Mod (.txt) < prev    next >
Encoding:
Oberon Text  |  1995-11-30  |  3.5 KB  |  102 lines  |  [TEXT/.Ob4]

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 30 Nov 95
  6. Syntax10b.Scn.Fnt
  7. MODULE Bitmaps;
  8. (* MK 1994-05-09 *) (* MAH 
  9.  for PowerMac *)
  10. (* Thanks to G
  11. nther Blaschek, Michael Franz, Matthias Hausner *)
  12. IMPORT Sys, SYSTEM, Display, Macintosh; 
  13.     Bitmap* = POINTER TO BitmapDesc;
  14.     BitmapDesc* = RECORD 
  15.         w-, h-: LONGINT;        (* wide and height of Bitmap *)
  16.         p: Sys.CGrafPort;
  17.         adr: POINTER TO ARRAY OF CHAR
  18.     END;
  19.     Disp-: Bitmap;        (* Bitmap representing the screen *)
  20. PROCEDURE ToRect(VAR r1: Sys.Rect; x, y, w, h: INTEGER);
  21. BEGIN
  22.     r1.left := x;
  23.     r1.right := x + w;
  24.     r1.bottom := y;
  25.     r1.top := y - h
  26. END ToRect;
  27. PROCEDURE CopyBlock* (sb, db: Bitmap; sx, sy, w, h, dx, dy, mode: INTEGER);
  28. (* copies a part of the source-Bitmap sb to the destination-Bitmap db *)
  29.     r1, r2: Sys.Rect;
  30.     s, d : Sys.PixMapRealPtr;
  31.     hdis, hdes, hsrc : Sys.PixMapRealHandle;
  32. BEGIN
  33.     Sys.HLock (db.p.portPixMap);
  34.     Sys.HLock (sb.p.portPixMap);
  35.     Sys.HLock (Disp.p.portPixMap);
  36.     hdes:=SYSTEM.VAL (Sys.PixMapRealHandle, db.p.portPixMap);
  37.     hsrc:=SYSTEM.VAL (Sys.PixMapRealHandle, sb.p.portPixMap);
  38.     hdis:=SYSTEM.VAL (Sys.PixMapRealHandle, Disp.p.portPixMap);
  39.     IF hdes.p = hdis.p THEN
  40.         Macintosh.SetPenScreen(TRUE, Macintosh.thePortClip, Display.white, mode)
  41.     END;
  42.     ToRect (r1, sx, SHORT (sb.h) -sy, w, h);
  43.     ToRect (r2, dx, SHORT (db.h) -dy, w, h);
  44.     s:=SYSTEM.VAL (Sys.PixMapRealPtr, hsrc.p);
  45.     d:=SYSTEM.VAL (Sys.PixMapRealPtr, hdes.p);
  46.     Sys.CopyBits2 (s^, d^, r1, r2, mode, 0);
  47.     (* releasing the memory of source-Bitmap, if source-Bitmap is not representing the screen *)
  48.     IF hsrc.p # hdis.p THEN  
  49. (*        Sys.DeAllocBlock (s.baseAddr);  *)
  50.         Sys.CloseCPort (sb.p) 
  51.     END;
  52.     Sys.HUnlock (db.p.portPixMap);
  53.     Sys.HUnlock (sb.p.portPixMap);
  54.     Sys.HUnlock (Disp.p.portPixMap);
  55. END CopyBlock;
  56. PROCEDURE New* (w, h: LONGINT): Bitmap;
  57. (* allocates a new Bitmap, which could be used from an Oberon-Programm *)
  58.     b: Bitmap;
  59.     rb: INTEGER;
  60.     p : Sys.PixMapRealPtr;
  61.     hand : Sys.PixMapRealHandle;
  62. BEGIN
  63.     (* allocating new Bitmap *)
  64.     NEW (b);
  65.     b.w := w;
  66.     b.h := h;
  67.     Sys.OpenCPort (b.p);
  68.     Sys.HLock (b.p.portPixMap);
  69.     hand:=SYSTEM.VAL (Sys.PixMapRealHandle, b.p.portPixMap);
  70.     p:=SYSTEM.VAL (Sys.PixMapRealPtr, hand.p);
  71.     ToRect (p.bounds, 0, SHORT (h), SHORT (w), SHORT (h));
  72.     (* calculating of rowBytes  must be even, should be a multiple of four *)
  73.     rb := ((p.pixelSize * SHORT (w)) + 15)  DIV 16 * 2;
  74.     p.rowBytes := MIN (INTEGER) + rb;
  75.     (* allocating space for image *)
  76. (* Sys.AllocBlock (adr, rb * h);  *)
  77.     SYSTEM.NEW (b.adr, rb * h);
  78.     p.baseAddr := SYSTEM.VAL (LONGINT, b.adr);
  79.     Sys.HUnlock (b.p.portPixMap);
  80.     ASSERT (b.adr#NIL);
  81.     (* returning new Bitmap *)
  82.     RETURN b 
  83. END New;
  84. PROCEDURE Init*;
  85. VAR p : Sys.PixMapRealPtr; hand : Sys.PixMapRealHandle;
  86. BEGIN
  87.     Display.SetColor (12, 210, 210, 210);
  88.     Display.SetColor (13, 150, 150, 150);
  89.     Display.SetColor (14, 100, 100, 100);
  90.     (* allocating a new Bitmap, which represents the screen *)
  91.     NEW (Disp);
  92.     Sys.OpenCPort (Disp.p);
  93.     Sys.HLock (Disp.p.portPixMap);
  94.     hand:=SYSTEM.VAL (Sys.PixMapRealHandle, Disp.p.portPixMap);
  95.     p:=SYSTEM.VAL (Sys.PixMapRealPtr, hand.p);
  96.     Disp.h := p.bounds.bottom - p.bounds.top;
  97.     Disp.w := p.bounds.right - p.bounds.left;
  98.     Sys.HUnlock (Disp.p.portPixMap);
  99. END Init;
  100. BEGIN Init
  101. END Bitmaps.
  102.